package com.yc.sole.erp.controller;

import com.yc.sole.erp.biz.OsOrderBiz;
import com.yc.sole.erp.request.OsOrderQueryReq;
import com.yc.sole.erp.request.OsOrderReq;
import com.yc.sole.erp.response.OsOrderResp;
import com.yc.sole.framework.mybatis.page.BaseBatchIdsReq;
import com.yc.sole.framework.mybatis.page.BasePageReq;
import com.yc.sole.framework.mybatis.page.Paging;
import com.yc.sole.framework.result.Result;
import com.yc.sole.framework.validate.DeleteGroup;
import com.yc.sole.framework.validate.SaveGroup;
import com.yc.sole.framework.validate.UpdateGroup;
import com.yc.sole.framework.web.PreAuth;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yizuomin
 * @date 2024-03-13
 **/
@Slf4j
@RestController
@RequiredArgsConstructor
public class OsOrderController {

    private final OsOrderBiz osOrderBiz;

    /**
     * 新增
     *
     * @param osOrderReq
     * @return RestResult
     */
    @PreAuth(value = "sale:os-order:save", description = "新增")
    @PostMapping("/api/sale/os-order/save")
    public Result<Void> saveOsOrder(@RequestBody @Validated(SaveGroup.class) OsOrderReq osOrderReq) {
        osOrderBiz.saveOsOrder(osOrderReq);
        return Result.success();
    }

    /**
     * 通过Id修改
     *
     * @param osOrderReq
     * @return RestResult
     */
    @PreAuth(value = "sale:os-order:update", description = "修改")
    @PostMapping("/api/sale/os-order/update")
    public Result<Void> updateOsOrderById(@RequestBody @Validated(UpdateGroup.class) OsOrderReq osOrderReq) {
        osOrderBiz.updateOsOrderById(osOrderReq);
        return Result.success();
    }

    /**
     * 通过id批量删除
     *
     * @param baseBatchIdsReq
     * @return RestResult
     */
    @PreAuth(value = "sale:os-order:delete", description = "删除")
    @PostMapping("/api/sale/os-order/delete")
    public Result<Void> deleteOsOrder(@RequestBody @Validated(DeleteGroup.class) BaseBatchIdsReq baseBatchIdsReq) {
        osOrderBiz.deleteOsOrderByIds(baseBatchIdsReq.getIds());
        return Result.success();
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return Result
     */
    @PreAuth(value = "sale:os-order:select", description = "查询")
    @PostMapping("/api/sale/os-order/{id}")
    public Result<OsOrderResp> selectOsOrderById(@PathVariable Long id) {
        return Result.data(osOrderBiz.selectOsOrderById(id));
    }

    /**
     * 分页查询
     *
     * @param basePageReq
     * @return Result
     */
    @PreAuth(value = "sale:os-order:select", description = "查询")
    @PostMapping("/api/sale/os-order/page")
    public Result<Paging<OsOrderResp>> selectOsOrderPage(@RequestBody @Validated BasePageReq<OsOrderQueryReq> basePageReq) {
        return Result.data(osOrderBiz.selectOsOrderPage(basePageReq.toPage(), basePageReq.getQuery()));
    }
}
